package it.blueocean.acanto.taglibrary.jsp.taglib.tags.dataset.filter;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Operators
{
	private static Properties operatorsMap_;

	private final static Logger logger_ = LoggerFactory.getLogger(Operators.class);

	public static String getExpression(String fieldName, String operator, boolean paramBoolean)
	{
		String str = operatorsMap_.getProperty(operator);
		if(str == null)
		{
			logger_.warn("operator " + operator + " was not mapped, using it as it is");
			str = operator;
		}
		str = str.replaceAll("\\$fieldName", fieldName);
		return str;
	}

	static
	{
		operatorsMap_ = new Properties();
		
		try
		{
			InputStream localInputStream = Operators.class.getResourceAsStream("operatorsMapping.properties");
			
			if(localInputStream == null)
			{
				throw new FileNotFoundException();
			}
			
			operatorsMap_.load(localInputStream);
		}
		catch (IOException localIOException)
		{
			logger_.warn("No operators mapping defined, resource operatorsMapping.properties not found");
		}
	}
}
